//
//  HTVisitorView.swift
//  WeiBoDemo
//
//  Created by 郝涛 on 16/4/17.
//  Copyright © 2016年 郝涛. All rights reserved.
//

import UIKit
import SnapKit
class HTVisitorView: UIView {

    
    //定义闭包
    var  ClickIncident: (()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //加载控件
        SetUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //定义一个方法供外界调用  显示不同的内容
     func SetVisitorViewContent(Text:String? ,ImageName:String?){
        
        if let text1 = Text , imgname=ImageName {
            //image
            houseImageView.image = UIImage(named: imgname)
            //text
            contentLabel.text = text1
            // 隐藏圆圈
            circleImageView.hidden = true
        }else{
            //显示首页
            circleImageViewAnimation()
        }
    }
    
    
    //让圈圈转起来
    private func circleImageViewAnimation(){
        
        //创建动画
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        //多长
        anim.duration = 20
        //多少次
        anim.repeatCount = MAXFLOAT
        //到哪里
        anim.toValue = 2 * M_PI
        
        //程序到后台后  动画会关闭
        anim.removedOnCompletion = false
        
        circleImageView.layer.addAnimation(anim, forKey: nil)
    }
    
    //添加控件
    func SetUpUI(){
        
        //设置视图的背景颜色 
        self.backgroundColor = RGB(red: 237, green: 237, blue: 237)
        //添加控件
        addSubview(houseImageView)
        addSubview(circleImageView)
        addSubview(coverImageView)
        addSubview(contentLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        
        
        //房子
        houseImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
         //圆圈
        circleImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        //遮罩
        coverImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        //label文字
        contentLabel.snp_makeConstraints { (make) -> Void in
            
            //label的顶部等于圆圈的底部+16
            make.top.equalTo(circleImageView.snp_bottom).offset(16)
            //label中心x
            make.centerX.equalTo(houseImageView.snp_centerX)
            //宽
            make.width.equalTo(230)
            //高
            make.height.equalTo(36)
        }
        //注册按钮
        registerButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(contentLabel.snp_left)
            make.top.equalTo(contentLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSizeMake(100, 36))
            
            
        }
       //登录按钮
        loginButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(contentLabel.snp_right)
            make.top.equalTo(contentLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSizeMake(100, 36))
        }
        
    }
    
    
    //房子懒加载
   private lazy var houseImageView:UIImageView = UIImageView(image: UIImage(named:"visitordiscover_feed_image_house"))
    
    //圆圈
   private lazy var circleImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    //遮罩
    private lazy var coverImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    
    //label文字
    private lazy var contentLabel:UILabel = {
        let contentLabel = UILabel()
        //颜色
        contentLabel.textColor = UIColor.orangeColor()
        //font
        contentLabel.font = UIFont.systemFontOfSize(14)
        //设置文字居中
        contentLabel.textAlignment = .Center
        contentLabel.numberOfLines = 0
        //设置文字
        contentLabel.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        
        return contentLabel
    }()
    //注册按钮
    private lazy var registerButton:UIButton = {
       
        let registerBtn = UIButton ()
        
        //监听
        registerBtn.addTarget(self, action: "clickBtn", forControlEvents: UIControlEvents.TouchUpInside)
        registerBtn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        //设置文字
        registerBtn.setTitle("注册", forState: UIControlState.Normal)
        
        //设置文字颜色
        registerBtn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        
        
        return registerBtn
    }()
    //登录按钮
    //注册按钮
    private lazy var loginButton:UIButton = {
        
        let loginBtn = UIButton ()
        loginBtn.addTarget(self, action: "clickBtn", forControlEvents: UIControlEvents.TouchUpInside)
        loginBtn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        //设置文字
        loginBtn.setTitle("登录", forState: UIControlState.Normal)
    
        //设置文字颜色
        loginBtn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        
        
        return loginBtn
        }()
    //点击事件
    func clickBtn(){
        
        ClickIncident!()
   
    }
    
    
    
    
}
